<?php
   
   include('lock.php'); 
    
   $total=$_POST['total'];
   $order_date=$_POST['order_date'];
   $location_id=$_POST['location_id'];

    //store into order table
    $sql="INSERT INTO `webtech`.`order` (`order_ID`, `order_total_price`, `order_date`, `order_status`, `location_ID`, `user_ID`) VALUES (NULL, '$total', '$order_date', 'Pending', '$location_id', '$login_session')";
    $q3=mysql_query($sql);
    //-- end of storing      
         
    //store into order_game table      
    $q=mysql_query("SELECT demo_ID FROM cart WHERE user_ID='$login_session'");
  
    while($data=mysql_fetch_array($q))
    {
      $demo_id=$data['demo_ID'];
      $ql=mysql_query("SELECT * FROM demo WHERE demo_ID='$demo_id'");
      
      while($data_fetch=mysql_fetch_array($ql))
      {
        $demo_price=number_format($data_fetch['demo_price'],2);
        $sql="SELECT `order_ID` FROM `order` WHERE user_ID ='$login_session'";
        $q2=mysql_query($sql);

        while($data_fetch2=mysql_fetch_array($q2))
        {  
            $order_id=$data_fetch2['order_ID'];
            $sql="INSERT INTO `webtech`.`order_game` (`order_game_ID`, `game_ID`, `game_price`, `order_ID`) VALUES (NULL, '$demo_id', '$demo_price', '$order_id')";
            $q3=mysql_query($sql);
        } 
      }
    }
         
  //remove from cart
  $sql_delete="DELETE FROM cart WHERE user_ID='$login_session'";
  mysql_query($sql_delete);
  //-- end of remove   
    
  echo"<br/>"."Items Checked-out";
?>